package com.example.waimai.util;

import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.utils.DistanceUtil;

import java.text.DecimalFormat;

/*
* 计算距离的工具类
* */
public class MyDistanceUtil {

    public static String formatDistance(LatLng current, LatLng other){
        double distance= DistanceUtil.getDistance(current, other);
        String str;
        if(distance>=1000){
            DecimalFormat df = new DecimalFormat("#.00");
            double b = distance/1000;
            str=df.format(b)+"千米";
        }else{
            DecimalFormat df = new DecimalFormat("######0");
            str = df.format(distance)+"米";
        }
        return str;
    }
}
